package com.grass.p019lv.activity;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.bean.TwoBean;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.bean.request.VarietyRequest;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.google.android.material.appbar.AppBarLayout;
import com.google.gson.Gson;
import com.grass.p019lv.adapter.AdapterVarietyInfo;
import com.grass.p019lv.databinding.ActivityVarietyInfoBinding;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

/* renamed from: com.grass.lv.activity.VarietyInfoActivity */
public class VarietyInfoActivity extends BaseActivity<ActivityVarietyInfoBinding> implements OnRefreshLoadMoreListener {
    String HTTP_TAG = "queryVideoByChoice";
    AdapterVarietyInfo adapter;
    public int choiceId;
    public String desc;
    public String imgString;
    int lastId = 0;
    public String name;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return R.layout.activity_variety_info;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        ViewGroup.LayoutParams layoutParams = ((ActivityVarietyInfoBinding) this.binding).ivHead.getLayoutParams();
        int windowWidth = (UiUtils.getWindowWidth() * 46) / 105;
        layoutParams.height = windowWidth;
        ((ActivityVarietyInfoBinding) this.binding).ivHead.setLayoutParams(layoutParams);
        GlideUtils.loadPic(this.imgString, ((ActivityVarietyInfoBinding) this.binding).ivHead);
        TextView textView = ((ActivityVarietyInfoBinding) this.binding).tvTitle;
        textView.setText("#" + this.name);
        ((ActivityVarietyInfoBinding) this.binding).tvDetails.setText(this.desc);
        ((ActivityVarietyInfoBinding) this.binding).refresh.setOnRefreshListener(this);
        ((ActivityVarietyInfoBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((ActivityVarietyInfoBinding) this.binding).tvBack.setOnClickListener(new View.OnClickListener() {
            /* class com.grass.p019lv.activity.VarietyInfoActivity.View$OnClickListenerC29231 */

            public void onClick(View view) {
                VarietyInfoActivity.this.finish();
            }
        });
        ((ActivityVarietyInfoBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.adapter = new AdapterVarietyInfo();
        ((ActivityVarietyInfoBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(new ItemClickListener() {
            /* class com.grass.p019lv.activity.VarietyInfoActivity.C29242 */

            @Override // com.androidx.p013lv.base.listener.ItemClickListener
            public void onItemClick(View view, int i) {
                VarietyInfoActivity varietyInfoActivity = VarietyInfoActivity.this;
                varietyInfoActivity.startVideoPlay(((VideoBean) varietyInfoActivity.adapter.getDataInPosition(i)).getVideoId());
            }
        });
        ((ActivityVarietyInfoBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.activity.VarietyInfoActivity.View$OnClickListenerC29253 */

            public void onClick(View view) {
                VarietyInfoActivity.this.lastId = 0;
                VarietyInfoActivity.this.getInfo();
            }
        });
        getInfo();
        final int actionBarHeight = windowWidth - (ImmersionBar.getActionBarHeight(this) + ImmersionBar.getStatusBarHeight(this));
        ((ActivityVarietyInfoBinding) this.binding).toolbar.getBackground().setAlpha(0);
        ((ActivityVarietyInfoBinding) this.binding).appBar.addOnOffsetChangedListener((AppBarLayout.OnOffsetChangedListener) new AppBarLayout.OnOffsetChangedListener() {
            /* class com.grass.p019lv.activity.VarietyInfoActivity.C29264 */

            @Override // com.google.android.material.appbar.AppBarLayout.BaseOnOffsetChangedListener, com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener
            public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
                if (i > (-actionBarHeight)) {
                    ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).toolbar.getBackground().setAlpha(((-i) * 255) / actionBarHeight);
                } else {
                    ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).toolbar.getBackground().setAlpha(255);
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (this.lastId == 0) {
            AdapterVarietyInfo adapterVarietyInfo = this.adapter;
            if (!(adapterVarietyInfo == null || adapterVarietyInfo.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((ActivityVarietyInfoBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((ActivityVarietyInfoBinding) this.binding).statusLayout.showLoading();
        }
        String queryVideoByChoice = UrlManager.getInsatance().queryVideoByChoice();
        VarietyRequest varietyRequest = new VarietyRequest();
        varietyRequest.setChoiceId(this.choiceId);
        varietyRequest.setPageSize(30);
        varietyRequest.setLastId(this.lastId);
        HttpUtils.getInsatance().post(queryVideoByChoice, new Gson().toJson(varietyRequest), new HttpCallback<BaseRes<TwoBean>>(this.HTTP_TAG) {
            /* class com.grass.p019lv.activity.VarietyInfoActivity.C29275 */

            public void onLvSuccess(BaseRes<TwoBean> baseRes) {
                ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).statusLayout.hideLoading();
                ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).refresh.finishRefresh();
                ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).refresh.finishLoadMore();
                if (baseRes.getCode() == 200) {
                    if (baseRes.getData() != null && baseRes.getData().getList() != null && baseRes.getData().getList().size() > 0) {
                        VarietyInfoActivity.this.adapter.setDomain(baseRes.getData().getDomain());
                        if (VarietyInfoActivity.this.lastId == 0) {
                            VarietyInfoActivity.this.adapter.setData(baseRes.getData().getList());
                            ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).refresh.resetNoMoreData();
                            return;
                        }
                        VarietyInfoActivity.this.adapter.setDatasInEnd(baseRes.getData().getList());
                    } else if (VarietyInfoActivity.this.lastId == 0) {
                        ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).statusLayout.showEmpty();
                    } else {
                        ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).refresh.finishLoadMoreWithNoMoreData();
                    }
                } else if (VarietyInfoActivity.this.lastId == 0) {
                    ((ActivityVarietyInfoBinding) VarietyInfoActivity.this.binding).statusLayout.showError();
                } else {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            }
        });
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        AdapterVarietyInfo adapterVarietyInfo = this.adapter;
        if (adapterVarietyInfo == null || adapterVarietyInfo.getData() == null || this.adapter.getData().size() == 0) {
            ((ActivityVarietyInfoBinding) this.binding).refresh.finishLoadMore();
            return;
        }
        this.lastId = ((VideoBean) this.adapter.getLastDataInPosition()).getVideoId();
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.lastId = 0;
        getInfo();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag(this.HTTP_TAG);
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityVarietyInfoBinding) this.binding).toolbar).init();
    }
}
